import {View, Text} from '@tarojs/components'
import {useState} from 'react'
import {useDidShow} from '@tarojs/taro'
import NavAside from './components/navAside'
import NavContent from './components/navContent'
import http from '../../http/http'
import './classify.less'

function Classify() {

  const [state, setstate] = useState()
  const [classify1, setClassify1] = useState([])
  const [classify2, setClassify2] = useState([])
  const [allClassify, setAllClassify] = useState([])

  // 获取分类数据
  useDidShow(() => {
    http({
      url: '/huangyi/getClassify',
      method: 'get'
    }).then(res => {
      console.log(res)
      setClassify1(res.data1)
      setClassify2(res.data2)
      res.data1.forEach(v1 => {
        res.data2.forEach(v2 => {
          v2.value = v2.name
          v2.image = v2.image_url
          if (v2.goods_classify_id === v1.id) {
            if (v1.children) {
              v1.children.push(v2)
            } else {
              v1.children = []
              v1.children.push(v2)
            }

          }
        })
      })
      setAllClassify(res.data1)
    })
  })

  return (
    <View className='classify'>
      <View className='tit'>
        分类
      </View>

      <View className='con'>
        <NavAside setstate={setstate} classify1={classify1} ></NavAside>
        <NavContent state={state} allClassify={allClassify} ></NavContent>
      </View>


    </View>
  )

}

export default Classify
